<script setup>
import { ref } from 'vue'
const rules = {
    userName: [
        { required: true, message: '请输入用户昵称', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '昵称必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ],
    phone: [
        { required: true, message: '请输入联系电话', trigger: 'blur' },
        { type: 'num', message: '电话不正确', trigger: 'blur' }
    ]
}
import {useAdmInfoStore} from '@/stores/adm.js'
const admInfoStore = useAdmInfoStore();
const admInfo = ref({...admInfoStore.info})
//修改用户信息
import {admInfoUpdateService} from '@/api/adm/adm.js'
import { ElMessage } from 'element-plus';
const updateAdmInfo = async ()=>{
    let result = await admInfoUpdateService(admInfo.value)
    ElMessage.success(result.data? result.data:'修改成功')
    //更新pinia中的数据
    admInfoStore.info.aname=admInfo.value.aname
    admInfoStore.info.phone = admInfo.value.phone
}
</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>基本资料</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="admInfo" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="学工号">
                        <el-input v-model="admInfo.userID" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="姓名" prop="userName">
                        <el-input v-model="admInfo.userName"></el-input>
                    </el-form-item>
                    <el-form-item label="联系电话" prop="phone">
                        <el-input v-model="admInfo.phone"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="updateAdmInfo">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>